// 
// task.h - Defines the structures and prototypes needed to multitask.
//          Written for JamesM's kernel development tutorials.
//

#ifndef TASK_H
#define TASK_H

#include "common.h"
#include "paging.h"
#include "signals.h"
#define MAX_TASKS 256
#define TASK_RUNNING 0
#define TASK_UNINTERRUPTABLE 1
#define TASK_INTERRUPTABLE 2
#define TASK_SLEEPING 3
struct math_state_s {
	long	cwd;
	long	swd;
	long	twd;
	long	fip;
	long	fcs;
	long	foo;
	long	fos;
	long	st_space[20];
};
// This structure defines a 'task' - a process.
typedef struct task
{
	int id;                // Process ID.
	u32int esp, ebp;       // Stack and base pointers.
	u32int eip;            // Instruction pointer.
	page_directory_t *page_directory; // Page directory.
	int stat, pri;
	int running, running_1;
	u32int (*sig[MAX_SIGS])(u32int, u32int);
	u32int sig_auth[MAX_SIGS];
	/* IPC stuff (Signal Queue and Message Queue) */
	struct sq_s {
		u32int num;
		u32int dat;
	} sq[128];
	struct msg_s {
		u8int used;
		u32int dat;
	} msg[128];
	u32int auth; //Authority
	u32int fable; //Can this task be focused?
	u32int stack; //Location of stack
	/* Sleeping info */
	u32int ticks_to_sleep;
	u32int start_tick_to_sleep;
	struct math_state_s math_state;
	int used_math;
	struct task *next;     // The next task in a linked list.
} task_t;

// Initialises the tasking system.
void initialize_tasking();

// Called by the timer hook, this changes the running process.
void task_switch();

// Forks the current process, spawning a new one with a different
// memory space.
int fork();

// Causes the current process' stack to be forcibly moved to a new location.
void move_stack(void *new_stack_start, u32int size);

// Returns the pid of the current process.
u32int getpid();

#endif

